<!-- Channel page -->
<script type="text/javascript">
<?php  $type = (isset($GET_type) && strlen($GET_type)) ? '/' . $GET_type : '/meilleurs-clients'; ?>
    var JSVAR_STATS_URL = '<?php  echo  Erra_System_PageBuilder::makeLink('stats') . $type ?>';
</script>

<?php 
$location = Msa_LocationObject::getLocationArray();
$location['-'] = 'Tous les lieux';
$filter_by_location = Erra_Fields_ComboBox::create('select_stats_location')
        ->fill($location)
        ->setDescription('Voir les statistiques pour');
if (is_numeric($GET_location)) {
    $_SESSION['retain_location'] = $GET_location;
} else if ($GET_location == '-') {
    $_SESSION['retain_location'] = '';
} else if (isset($_SESSION['retain_location']) && is_numeric($_SESSION['retain_location'])) {
    $GET_location = $_SESSION['retain_location'];
}
$filter_by_location->setValue($GET_location);
$filter_by_location = $filter_by_location->edit();
?>
<div id="right">
    <div class="page-content">
        <div class="header-content stats-gradient">
            <table><tr><td><img src="<?php  echo  config_get('public_images') ?>/header/header_statistiques.png"/>
                    </td><td>Statistiques</td></tr></table>
        </div>
        <div class="inner-content left-menu-inner">
            <ul class="split-right-menu stat-list">
                <li class = "top-level stats-rendezvous">
                    Rendez-vous
                    <ul class = "sub-item">
                        <li><a href = "<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/rdv-ca-realise') . '/' . $GET_location ?>">Chiffre d'affaires réalisé</a></li>
                        <li><a href = "<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/rdv') . '/' . $GET_location ?>">Tous les RDV</a></li>
                        <li><a href = "<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/rdv-pris-internet') . '/' . $GET_location ?>">RDV pris sur internet</a></li>
                        <li><a href = "<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/rdv-ca') . '/' . $GET_location ?>">Chiffre d'affaires non venu</a></li>
                        <li><a href = "<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/rdv-categories') . '/' . $GET_location ?>">Catégories</a></li>
                    </ul>
                </li>
                <li class="top-level stats-clients">
                    Statistiques client
                    <ul class="sub-item">
                        <li><a href="<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/meilleurs-clients') . '/' . $GET_location ?>">Meilleurs clients</a></li>
                    </ul>
                </li>
                <li class="top-level stats-prestations">
                    Prestations
                    <ul class="sub-item">
                        <li><a href="<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/prestations-plus-reservees') . '/' . $GET_location ?>">Les meilleures prestations</a></li>
                    </ul>
                </li>
                <li class="top-level stats-agenda">
                    Agendas
                    <ul class="sub-item">
                        <li><a href="<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/agendas-plus-bookes') . '/' . $GET_location ?>">Les agendas les plus bookés</a></li>
                        <li><a href="<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/agendas-plus-utilises') . '/' . $GET_location ?>">Les agendas les plus utilisés</a></li>
                        <?php 
                        $query = 'SELECT COUNT(id) as nb_location FROM msa_locationobject';
                        $result = Erra_Core_DatabasePdo::SELECT($query);
                        if (Erra_Core_DatabasePdo::rowCount()) {
                            $row = $result->fetch();
                            if ($row->nb_location > 1) {
                                echo "<li><a href=" . Erra_System_PageBuilder::makeAjaxLink("stats/lieux-les-plus-bookes") . ">Les lieux les plus bookés</a></li>";
                                echo "<li><a href=" . Erra_System_PageBuilder::makeAjaxLink("stats/lieux-par-remplissage") . ">Les lieux par taux de remplissage</a></li>";
                            }
                        }
                        ?>
                    </ul>
                </li>
                <li class = "top-level stats-commandes">
                    Commandes
                    <ul class = "sub-item">
                        <li><a href = "<?php  echo  Erra_System_PageBuilder::makeAjaxLink('stats/ratio-commandes') . '/' . $GET_location ?>">Ratio commandes internet / internes</a></li>
                    </ul>
                </li>
            </ul>
            <div class = "split-content split-content-stats">
                <?php 
                if (isset($GET_type) && $GET_type == 'prestations-plus-reservees') {
                    $res .= $filter_by_location;

                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul des meilleures prestations...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayBarChart(Tools_StatsObject::dataGetBestPrestations($GET_location));
                } else if (isset($GET_type) && $GET_type == 'agendas-plus-bookes') {
                    $res .= $filter_by_location;
                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul du booking des agendas...</i></div>';

                    $res .= Tools_StatsDisplayObject::displayBarChart(Tools_StatsObject::dataGetBestAgendasUse($GET_location), '#FCA4A4');
                } else if (isset($GET_type) && $GET_type == 'agendas-plus-utilises') {
                    $res .= $filter_by_location;

                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul du taux d\'utilisation des agendas...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayBarChart(Tools_StatsObject::dataGetBestAgendasUseTime($GET_location));
                } else if (isset($GET_type) && $GET_type == 'lieux-les-plus-bookes') {
                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul du booking des lieux...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayBarChart(Tools_StatsObject::dataGetLocationUse());
                } else if (isset($GET_type) && $GET_type == 'lieux-par-remplissage') {
                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul du taux de remplissage...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayBarChart(Tools_StatsObject::dataGetLocationUseTime());
                } else if (isset($GET_type) && $GET_type == 'ratio-commandes') {
                    $res .= $filter_by_location;

                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul du ratio de commandes...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayPieChart(Tools_StatsObject::dataGetCommandeRatio($GET_location));
                } else if (isset($GET_type) && $GET_type == 'rdv') {
                    $res .= $filter_by_location;

                    $res .= '';
                    $res .= '';
                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul des ventes...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayStockChart(Tools_StatsObject::getCommandesByTime($GET_location));
                } else if (isset($GET_type) && $GET_type == 'rdv-pris-internet') {
                    $res .= $filter_by_location;

                    $res .= '';
                    $res .= '';
                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul des rendez-vous internet...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayStockChart(Tools_StatsObject::getCommandesInternet($GET_location));
                } else if (isset($GET_type) && $GET_type == 'rdv-ca') {
                    $res .= $filter_by_location;

                    $res .= '';
                    $res .= '';
                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul du chiffre d\'affaire "pas venus"...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayStockChart(Tools_StatsObject::getCAPasVenu($GET_location));
                } else if (isset($GET_type) && $GET_type == 'rdv-categories') {
                    $res .= $filter_by_location;
                    $res .= '';
                    $res .= '';
                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Calcul des catégories...</i></div>';

                    $res .= Tools_StatsDisplayObject::displayPieChart(Tools_StatsObject::dataGetCategoriesRatio($GET_location));
                } else if (isset($GET_type) && $GET_type == 'meilleurs-clients') {
                    $res .= $filter_by_location;

                    $res .= '';
                    $res .= '<div id="dasbhoard-content" style="height: 500px; min-width: 700px; text-align:center;"><i>Définition des meilleurs clients...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayBarChart(Tools_StatsObject::dataGetBestClients($GET_location), '#88E895');
                } else {
                    $res .= '<div id="dasbhoard-content" style="height: 400px; min-width: 700px; text-align:center; margin-top:50px;"><i>Calcul des ventes...</i></div>';
                    $res .= Tools_StatsDisplayObject::displayStockChart(Tools_StatsObject::getCommandesCaByTime());
                }

                echo $res;
                ?>
            </div>
        </div>
    </div>
</div>


